package com.ying.tests.log;

import cn.hutool.core.lang.UUID;
import org.slf4j.MDC;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TraceInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // traceId
        MDC.put(TraceConstants.LOG_TRACE_ID, UUID.randomUUID().toString().replace("-", ""));
        return true;
    }

}
